package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;

import bean.Customer;
import dao.MySql;

public class WaitingCustSave extends HttpServlet implements Servlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			String func = request.getParameter("func");
			if(func==null||func.trim().length()==0)func = "xfunc";
			int id = Integer.parseInt(request.getParameter("id"));
			String name = request.getParameter("name");
			String email = request.getParameter("email");
			Customer cust = new Customer();
			cust.setWaitListId(id);
			cust.setEmail(email);
			cust.setName(name);
			new MySql().saveWaitCust(cust);
    		PrintWriter pw = response.getWriter();
    		JSONArray ja = new JSONArray();
   	        ja.add("ok");
			pw.println(func+" (\n"+ja+");\n");
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
